def consume():
    while True:
        number = yield
        print("开始消费",number)


consumer = consume()  # 生成器对象
next(consumer)  # 触发yield


for num in range(5):
    print("开始生产",num)
    consumer.send(num)



# # 使用列表推导式创建一个生成器
# gen = (x * x for x in range(10))
# print(gen)
# # 使用 next() 获取生成器的下一个元素
# print(next(gen))  # 输出: 0
# print(next(gen))  # 输出: 1
# print(next(gen))  # 输出: 4
#
# for i in gen:
#     print(i)
